#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>

#include "ServerFrameWork.h"

#define LOG_CONF_FILE "./test_sfw_log.xml"
#define LISTEN_IP "127.0.0.1"
#define LISTEN_PORT 8888

using std::cout;
using std::endl;

ServerFrameWork g_sfw;

int handle_socket_input(int fd, void * arg) {
	cout << "incomding socket event, fd:" << fd << endl;
	char buf[1024];
	bzero(buf, sizeof(buf));
	int len = recv(fd, buf, sizeof(buf), 0);
	if (len < 1) return len;
	cout << "recv " << len << " bytes from fd:" << fd << ", content:" << buf << endl;
	return 1;
}

int init() {
	g_sfw.init_logger(LOG_CONF_FILE);
	g_sfw.init(10, handle_socket_input, NULL, LISTEN_IP, LISTEN_PORT, 100, NULL, NULL);
}


int test() {
	g_sfw.start_server();
	return 0;
}
int main(int argc, char * argv[]) {

	init();

	test();

	return 0;
}
